package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseShowLogic {
	return &HouseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseShowLogic) HouseShow(in *house.HouseShowRequest) (*house.HouseShowResponse, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{}
	err := h.HouseGetInfo(int(in.HouseId))
	if err != nil {
		logx.Info("房源详情查看信息失败")
		return nil, errors.New("创建房源详情查看信息失败")
	}

	return &house.HouseShowResponse{
		HouseId:    int64(h.ID),
		HouseName:  h.HouseName,
		Address:    h.Address,
		HouseType:  h.HouseType,
		HouseFloor: h.HouseFloor,
		Price:      h.Price,
		HouseArea:  h.HouseArea,
		HouseCover: h.HouseCover,
	}, nil
}
